package com.api.pay.config;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.AlipayConfig;
import com.alipay.api.DefaultAlipayClient;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Administrator
 */
@Configuration
@Data
public class AlipayConfiguration {
    @Autowired
    private ApiPayConfig apiPayConfig;
    @Bean
    public AlipayClient alipayClient() throws AlipayApiException {
        AlipayConfig alipayConfig = new AlipayConfig();
        alipayConfig.setServerUrl(apiPayConfig.getServerUrl());
        alipayConfig.setAlipayPublicCertPath("C:\\Users\\Administrator\\Desktop\\student\\MarkDown\\project\\api-platform\\api-pay\\src\\main\\resources\\cert\\alipayCertPublicKey_RSA2.crt");
        alipayConfig.setAppCertPath("C:\\Users\\Administrator\\Desktop\\student\\MarkDown\\project\\api-platform\\api-pay\\src\\main\\resources\\cert\\appCertPublicKey_2021004152613293.crt");
        alipayConfig.setRootCertPath("C:\\Users\\Administrator\\Desktop\\student\\MarkDown\\project\\api-platform\\api-pay\\src\\main\\resources\\cert\\alipayRootCert.crt");
        alipayConfig.setAppId(apiPayConfig.getAppId());
        alipayConfig.setPrivateKey(apiPayConfig.getPrivateKey());
        alipayConfig.setFormat(apiPayConfig.getFormat());
        alipayConfig.setCharset(apiPayConfig.getCharset());
        alipayConfig.setSignType(apiPayConfig.getSignType());
        return new DefaultAlipayClient(alipayConfig);
    }
}
